home *** CD-ROM | disk | FTP | other *** search
/ Grapevine 5 / Grapevine 5.adf / grapevine5 / TAKEOVER.S < prev   
Encoding:
Text File  |  1990-09-07  |  7.6 KB  |  180 lines

  1.            Section  takeover,Code
  2.  
  3.            Opt      C-,O+,w-
  4.  
  5. Start:     lea      $dff000,a5          ; hardware base address
  6.                                         ; needed to allow address register with
  7.                                         ; offset to access hardware resisters
  8.  
  9.            Move.w   $1c(a5),OldInt      ; Save Old Interupts (INTENAR, save the
  10.                                         ; contents of interupt enable bits read)
  11.  
  12.            Move.w   $02(a5),OldDma      ; Save Old DMA (DMACONR, save the
  13.                                         ; contents of DMA control bits read)
  14.  
  15.            Move.w   #$7fff,$96(a5)      ; Clear DMA (turn all DMA channels
  16.                                         ; etc. off)
  17.  
  18.            Move.w   #$7fff,$9a(a5)      ; Clear Interupts  (turn all Interupts
  19.                                         ; off)
  20.  
  21.            Move.w   #$7fff,$9c(a5)      ; Clear Interupt Requests  (turn all
  22.                                         ; interupt requests etc. off)
  23.            Move.b   #$7f,$bfed01        ; kill timers
  24.  
  25.            Move.l   $6c.w,OldV3         ; save addess of the level 3 interupt
  26.                                         ; routine
  27.  
  28.            Move.l   #my_level3,$6c.w    ; put new interupt level 3 server
  29.                                         ; address in level 3 vector
  30.  
  31.            Move.l   #my_copper,$80(a5)  ; put address of my copperlist into
  32.                                         ; COP1LCH
  33.  
  34.            Lea      Sprites+2,a0        ; This bit points all the sprites to
  35.            Move.l   #Dumsprite,d0       ; a dummy sprite to prevent them from
  36.            Move.w   #7,d1               ; leaving vertical lines all over!
  37. Clrsprite:                              ;
  38.            Swap     d0                  ; Get low word of address
  39.            Move.w   d0,(a0)             ; put it in copper list
  40.            Swap     d0                  ; Get high word
  41.            Move.w   d0,4(a0)            ; put it in copper list
  42.            Add.l    #8,a0               ; point to next entry in copper list
  43.            Dbra     d1,Clrsprite        ; Do all 8 sprites
  44.  
  45.            Move.w   #$c010,$9a(a5)      ; Start interupts (turn on the level 3
  46.                                         ; interupt)
  47.  
  48.            Move.w   #$83ef,$96(a5)      ; Start DMA ( all DMA except disk DMA)
  49.  
  50.            Move.w   #1,$88(a5)          ; Strobe for copper start (needed
  51.                                         ; because graphics library is no longer
  52.                                         ; automatically strobing for the copper
  53.                                         ; to restart)
  54.  
  55.  
  56.            ********************
  57.            bsr      my_programme        ; this is where your program goes
  58.            ********************
  59.  
  60.  
  61.  
  62.            ; this section now returns control back the OS, if you packing below
  63.            ; $20000, your demo should not be able to quit and therefore should
  64.            ; not do the following, if you wish to exit you must put the reset
  65.            ; routine given later here (instead of the OS Restore). The demo will
  66.            ; just Guru if you try to exit when it is absolute packed to low a
  67.            ; address
  68.  
  69.  
  70.            ; ****** OS restore ******
  71.  
  72.            lea      $dff000,a5          ; hardware base address
  73.  
  74.            Move.l   OldV3,$6c.w         ; restore old level 3 vector
  75.  
  76.            Lea      GfxLib,a1           ; Pointer to Library Text
  77.  
  78.            move.l   4.w,a6              ; Get the address of exec library
  79.  
  80.            jsr      -132(a6)            ; Forbid() - this is needed because
  81.                                         ; the old level 3 interupt is now
  82.                                         ; running again
  83.  
  84.            Move.l   4.w,a6              ; Exec base
  85.            Moveq.l  #0,d0               ; Clear D0
  86.            Jsr      -$228(a6)           ; OpenLibrary() - opening the gfx
  87.                                         ; library gives you the addresses of
  88.                                         ; the old copperlists
  89.            cmp.l    #0,d0               ; if gfx library not open dont restore
  90.            beq      no_gfx_lib          ; copper library, this can cause a
  91.                                         ; crash if the demo is packed below
  92.                                         ; $20000 and the reason you shouldn't
  93.                                         ; exit
  94.  
  95.            Move.l   d0,a1               ; move the address of the gfx library
  96.                                         ; into a1 for offset addressing
  97.  
  98.            Move.l   $26(a1),$80(a5)     ; restore address of CLI copper 1
  99.            Move.l   $32(a1),$84(a5)     ; restore address of CLI copper 2
  100.                                         ; from the gfx library.
  101. no_gfx_lib:
  102.            Move.w   OldInt,d0           ; start old interupts
  103.            Or.w     #$8000,d0           ; enables you to set bits 0-14
  104.            Move.w   d0,$9a(a5)          ; set INTENA
  105.            Move.w   OldDma,d0           ; start old DMA
  106.            Or.w     #$8000,d0           ; enables you to set bits 0-14
  107.            Move.w   d0,$96(a5)          ; set DMACON
  108.  
  109.            Move.b   #$9b,$bfed01        ; Re-start CIA Timers
  110.  
  111.            Move.l   4.w,a6              ; Close Gfx lib
  112.            Jsr      -$19e(a6)
  113.  
  114.            move.l   4.w,a6
  115.            jsr      -138(a6)            ; Permit()
  116.  
  117.            Moveq.l  #0,d0               ; No errors, always clear before
  118.                                         ; returning to prevent RETURN CODE
  119.                                         ; errors on the CLI
  120.            Rts                          ; Exit
  121.  
  122.  
  123. my_level3:
  124.            Movem.l  d0-d7/a0-a6,-(a7)   ; New copper
  125.            Move.w   #$10,$dff09c        ; Serviced Interupt
  126.  
  127.            ****************
  128.            bsr      my_interupt         ; your stuff goes here
  129.            ****************
  130.  
  131. Exit:      Movem.l  (a7)+,d0-d7/a0-a6   ; Return from Interupt
  132.            Rte
  133.  
  134.            section  Copperdata,data_c   ; force to chipmem
  135.  
  136. my_copper:
  137.            dc.w     $100,$0200          ; no bitpplanes
  138.            dc.w     $104,$a             ; bp control reg
  139.            dc.w     $108,0              ; bp modulo - odd
  140.            dc.w     $10a,0              ; bp modulo - even
  141.            dc.w     $180,0              ; colour 0 to black
  142.            dc.w     $102,0              ; no scroll
  143.  
  144.            dc.w     $08e,$2c81          ; bp window start left
  145.            dc.w     $090,$2cc1          ; bp window bot right
  146.            dc.w     $094,$d0            ; bp stop horz
  147.            dc.w     $92,$38
  148.  
  149. sprites:   dc.w     $120,0,$122,0,$124,0,$126,0   ; Sprite pointers should
  150.            dc.w     $128,0,$12a,0,$12c,0,$12e,0   ; be pointed to a location
  151.            dc.w     $130,0,$132,0,$134,0,$136,0   ; which is initialised to
  152.            dc.w     $138,0,$13a,0,$13c,0,$13e,0   ; 0
  153.  
  154.            dc.w     $ffe1,$fffe              ; end of ntsc screen
  155.            dc.w     $3001,$ff00              ; end of pal screen
  156.            dc.w     $9c,$8010                ; irq set bits - restart copper
  157.            dc.w     $ffff,$fffe              ; end of copper list
  158.  
  159.  
  160.            Section  Variables,Data           ; This is where the old system
  161.                                              ; pointers etc are saved
  162.  
  163. DumSpite:  dc.l     0,0
  164. oldint:    dc.l     0
  165. olddma:    dc.l     0
  166. oldv3:     dc.l     0
  167. gfxlib:    dc.b     "graphics.library",0
  168.            even
  169.  
  170.            ; End of takover/return control routine
  171.  
  172.  
  173.            ; This is the reset routine, use this to reset the computer
  174.            ; when exiting a demo packed to a low address
  175.  
  176.            move.l   #$fc00d0,$80        ; Address of reset routine in rom
  177.            trap     #0                  ; call reset routine in supervisor mode
  178.  
  179.  
  180.